package com.cardone.platform.common.function;

import com.cardone.context.function.Execution2Function;
import com.cardone.platform.usercenter.dto.UserDto;
import org.apache.commons.collections.MapUtils;

import java.util.Map;

/**
 * Created by Administrator on 2015/3/23.
 */
public class OutputMapUserFunction implements Execution2Function<Map<String, Object>, Map<String, Object>, Object> {
    @Override
    public Map<String, Object> execution(Map<String, Object> parameterMap, Object returnData) {
        if (returnData == null) {
            return parameterMap;
        }

        if (!(returnData instanceof Map)) {
            return parameterMap;
        }

        Map<String, Object> returnMap = (Map<String, Object>) returnData;

        UserDto user = (UserDto) MapUtils.getObject(returnMap, "user");

        parameterMap.put("userId", user.getId());
        parameterMap.put("userCode", user.getCode());
        parameterMap.put("userName", user.toString());
        parameterMap.put("id", user.getId());

        return parameterMap;
    }
}
